package com.rpc.connection;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

//专门提供zookeeper 链接的自定义类型
public class ZkConnection {

    //保存zk 的地址 格式是 ip:port
    private String zkServer;

    //保存会话的超时时间
    private int sessionTimeout;

    public ZkConnection(){
        super();
        //设置默认值
        new ZkConnection("localhost:2181", 10000);
    }

    public ZkConnection(String zkServer, int sessionTimeout) {
        this.zkServer = zkServer;
        this.sessionTimeout = sessionTimeout;
    }


    public ZooKeeper getConection() throws IOException {
        return new ZooKeeper(zkServer, sessionTimeout, new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {

            }
        });
    }
}
